package com.zkingsoft.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;
import com.matrix.core.tools.UUIDUtil;
import com.matrix.core.tools.WebUtil;
import com.zkingsoft.bean.BizCollageDetail;
import com.zkingsoft.common.bean.SysUsers;
import com.zkingsoft.dao.BizCollageDetailDao;
import com.zkingsoft.service.BizCollageDetailService;

/**
 * @description service接口实现类(拼团详情)
 * @author 何明
 * @date 2018-05-23 00:08
 */
@Service
public class  BizCollageDetailServiceImpl implements  BizCollageDetailService{

	
	@Autowired
	private BizCollageDetailDao bizCollageDetailDao;
	
	
	@Override
	public int add(BizCollageDetail bizCollageDetail){
		// 设置基本字段信息
	/*	SysUsers loginUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
		bizCollageDetail.setCreateBy(loginUser.getSuName());
		bizCollageDetail.setUpdateBy(loginUser.getSuName());
		bizCollageDetail.setDetId(UUIDUtil.getRandomID());*/
		return bizCollageDetailDao.insert(bizCollageDetail);
		
	}
	
	@Override
	public int batchAdd(List<BizCollageDetail>  bizCollageDetailList) {
		//这里没有做基本字段的设置，如有需要请自己实现	
		int num = 0;
		int c = 10000;
		int size = bizCollageDetailList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= bizCollageDetailList.size() ? bizCollageDetailList.size() : end;
			List<BizCollageDetail> insertList = bizCollageDetailList.subList(begin, end);
			num += bizCollageDetailDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(BizCollageDetail oldBizCollageDetail
	,BizCollageDetail newBizCollageDetail){
	
		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(oldBizCollageDetail, newBizCollageDetail)) {
				return MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(oldBizCollageDetail, newBizCollageDetail);
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newBizCollageDetail);
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("detId", oldBizCollageDetail.getDetId());
			bizCollageDetailDao.updateByMap(modifyMap);
		}
		return MatrixConstance.DML_SUCCESSS;
	}
	
	@Override
	public int modifyByModel(BizCollageDetail bizCollageDetail){
	
		return bizCollageDetailDao.updateByModel(bizCollageDetail);
	
	}
	
	
	
	@Override
	public int remove(List<String> list){
	
		return bizCollageDetailDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(String detId){
	
		return bizCollageDetailDao.deleteById(detId);
	
	}
	
	@Override
	public int removeByModel(BizCollageDetail bizCollageDetail){
	
		return bizCollageDetailDao.deleteByModel(bizCollageDetail);
	
	}
	
	
	@Override
	public List<BizCollageDetail> findInPage(BizCollageDetail bizCollageDetail,  PaginationVO pageVo){
	
		return bizCollageDetailDao.selectInPage(bizCollageDetail , pageVo);
	
	}
	
	@Override
	public List<BizCollageDetail> findByModel(BizCollageDetail bizCollageDetail){
	
		return bizCollageDetailDao.selectByModel(bizCollageDetail);
	
	}
	
	@Override
	public int  findTotal(BizCollageDetail bizCollageDetail){
	
		return bizCollageDetailDao.selectTotalRecord(bizCollageDetail);
	
	}
	
	@Override
	public BizCollageDetail  findById(String detId){
	
		return bizCollageDetailDao.selectById(detId);
	
	}

   	
	
	
}